package com.hzt.agprosaleplatform.mapper;

import com.hzt.agprosaleplatform.entity.FinanceApplicationVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface AdminFinanceMapper {

    @Select("SELECT fa.finance_id, fa.user_id, fa.shop_id, fa.goods_id, fa.amount, fa.purpose, fa.term, fa.interestRate, fa.status, fa.applyTime, fa.audit_time as auditTime, fa.audit_opinion as auditOpinion, u.username FROM t_finance_application fa " +
            "LEFT JOIN t_user u ON fa.user_id = u.uid " +
            "ORDER BY fa.applyTime DESC")
    List<FinanceApplicationVO> selectAllApplications();

    @Update("UPDATE t_finance_application SET status = #{status}, audit_opinion = #{auditOpinion} WHERE finance_id = #{financeId}")
    int updateStatus(@Param("financeId") Integer financeId,
                     @Param("status") Integer status,
                     @Param("auditOpinion") String auditOpinion);
                     
    @Update("UPDATE t_finance_application SET status = #{status}, audit_opinion = #{auditOpinion}, audit_time = #{auditTime} WHERE finance_id = #{financeId}")
    int updateStatusWithTime(@Param("financeId") Integer financeId,
                             @Param("status") Integer status,
                             @Param("auditOpinion") String auditOpinion,
                             @Param("auditTime") Date auditTime);
}